package test5.lupeng.jf.com.teamdemo.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;

import test5.lupeng.jf.com.teamdemo.R;
import test5.lupeng.jf.com.teamdemo.bean.response.BlogCommentResponse;

/**
 * Created by C-yx on 2017/7/31.
 */

public class BlogCommentAdapter extends RecyclerView.Adapter {
    ArrayList<BlogCommentResponse.ResultBean> mResultBeen;

    public BlogCommentAdapter(ArrayList<BlogCommentResponse.ResultBean> mResultBeen) {
        this.mResultBeen = mResultBeen;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view  = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_blog_comment,parent,false);
        ItemViewHolder holder  = new ItemViewHolder(view);
        return holder;
    }
    class  ItemViewHolder extends RecyclerView.ViewHolder{
       ImageView iv_headImage;
        TextView tv_username;
        TextView tv_comment_content;
        public ItemViewHolder(View itemView) {
            super(itemView);
            iv_headImage=  itemView.findViewById(R.id.iv_headImage);
            tv_username=   itemView.findViewById(R.id.tv_username);
            tv_comment_content=   itemView.findViewById(R.id.tv_comment_content);
        }
    }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
       BlogCommentResponse.ResultBean bean =mResultBeen.get(position);
        ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
        itemViewHolder.tv_username.setText(bean.getAuthor().getUsername());
        Glide.with(holder.itemView.getContext()).load(bean.getAuthor().getHeadProtrait())
                .asBitmap()
                .into(itemViewHolder.iv_headImage);
        itemViewHolder.tv_comment_content.setText(bean.getContent());
    }

    @Override
    public int getItemCount() {
        return mResultBeen.size();
    }
}
